﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace M1Xonix
{
    class LevelUpScreen: GameScreen
    {
        private ContentManager _content;
        private Texture2D _background;
        private int _screenWidth;
        private int _screenHeight;
        private SpriteFont _font;
        private SpriteFont _boldFont;
        private int _levelScore;
        private float _percentageOwned;

        public LevelUpScreen(int levelScore, float percentageOwned)
        {
            IsPopup = true;
            _levelScore = levelScore;
            _percentageOwned = percentageOwned;
        }

        public override void LoadContent()
        {
            _screenWidth = ScreenManager.GraphicsDevice.Viewport.Width;
            _screenHeight = ScreenManager.GraphicsDevice.Viewport.Height;

            _content = new ContentManager(ScreenManager.Game.Services, "Content");
            _background = _content.Load<Texture2D>("background");
            _font = _content.Load<SpriteFont>("Arial");
            _boldFont = _content.Load<SpriteFont>("ArialBold");
        }

        public override void UnloadContent()
        {
            _content.Unload();
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch sprites = ScreenManager.SpriteBatch;
            sprites.Begin();

            int x = _screenWidth/2 - 200;
            int y = _screenHeight/2 - 100;
            sprites.Draw(_background, new Rectangle(x, y, 400,200), Color.Red);
            sprites.DrawString(_boldFont, "Level up!",new Vector2(x+30, y+30),Color.Yellow);
            sprites.DrawString(_font, "Area owned: " + Math.Round(_percentageOwned,0) + " %",new Vector2(x+50, y+70),Color.Yellow);
            sprites.DrawString(_font, "Level score: " + _levelScore,new Vector2(x+50, y+110),Color.Yellow);
            string spaceOrStartToContinue = "<space> or <start> to continue";
            sprites.DrawString(_font, spaceOrStartToContinue, new Vector2((x+200) - _font.MeasureString(spaceOrStartToContinue).X / 2, y+170),Color.Yellow);

            sprites.End();
        }

        public override void HandleInput(InputState input)
        {
            KeyboardState keys = input.CurrentKeyboardStates[(int)ControllingPlayer.Value];
            GamePadState pad = input.CurrentGamePadStates[(int) ControllingPlayer.Value];

            if(pad.IsButtonDown(Buttons.Start) || keys.IsKeyDown(Keys.Space))
            {
                ExitScreen();
            }
        }
    }
}
